<?php
/**
 * Created by PhpStorm.
 * User: guokunsheng
 * Date: 2018/6/21
 * Time: 16:50
 */

namespace app\common\model;

use app\common\lib\exception\ApiException;
use think\Cache;

class HeText extends Base
{

    /**
     * 获取所有合盘相位词条
     */
    public function getHeText()
    {
        $data = false;

        if ((int)($this->cache_on >= 1))
        {
            $data = Cache::get('he_text');
        }

        if ($data === false)
        {
            try
            {
                $data = $this->where('status', 0)->selectOrFail();
                $data = json_decode(json_encode($data, true), true);
            }
            catch (\Exception $e)
            {
                $data = [];
            }

            $temp = [];
            foreach ($data as $d) $temp[$d['planet'] . '-' . $d['phase']] = $d;
            $data = $temp;

            if ($this->cache_on >= 1)
            {
                Cache::set('he_text', $data, 86400 * 7);
            }
        }

        return $data;
    }

}
